rtc22 2.2.1
Loading...
Searching...
No Matches
rtc22.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2026 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
27
28#ifndef RTC22_H
29#define RTC22_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
58
63
68
73#define RTC22_REG_HUNDREDTHS 0x00
74#define RTC22_REG_SECONDS 0x01
75#define RTC22_REG_MINUTES 0x02
76#define RTC22_REG_HOURS 0x03
77#define RTC22_REG_DATE 0x04
78#define RTC22_REG_MONTHS 0x05
79#define RTC22_REG_YEARS 0x06
80#define RTC22_REG_WEEKDAYS 0x07
81#define RTC22_REG_HUNDREDTHS_ALARM 0x08
82#define RTC22_REG_SECONDS_ALARM 0x09
83#define RTC22_REG_MINUTES_ALARM 0x0A
84#define RTC22_REG_HOURS_ALARM 0x0B
85#define RTC22_REG_DATE_ALARM 0x0C
86#define RTC22_REG_MONTHS_ALARM 0x0D
87#define RTC22_REG_WEEKDAYS_ALARM 0x0E
88#define RTC22_REG_STATUS 0x0F
89#define RTC22_REG_CONTROL1 0x10
90#define RTC22_REG_CONTROL2 0x11
91#define RTC22_REG_INT_MASK 0x12
92#define RTC22_REG_SQW 0x13
93#define RTC22_REG_CAL_XT 0x14
94#define RTC22_REG_CAL_RC_HI 0x15
95#define RTC22_REG_CAL_RC_LOW 0x16
96#define RTC22_REG_SLEEP_CONTROL 0x17
97#define RTC22_REG_TIMER_CONTROL 0x18
98#define RTC22_REG_TIMER 0x19
99#define RTC22_REG_TIMER_INITIAL 0x1A
100#define RTC22_REG_WDT 0x1B
101#define RTC22_REG_OSC_CONTROL 0x1C
102#define RTC22_REG_OSC_STATUS 0x1D
103#define RTC22_REG_CONFIGURATION_KEY 0x1F
104#define RTC22_REG_TRICKLE 0x20
105#define RTC22_REG_BREF_CONTROL 0x21
106#define RTC22_REG_AFCTRL 0x26
107#define RTC22_REG_BATMODE_IO 0x27
108#define RTC22_REG_ID0 0x28
109#define RTC22_REG_ID1 0x29
110#define RTC22_REG_ID2 0x2A
111#define RTC22_REG_ID3 0x2B
112#define RTC22_REG_ID4 0x2C
113#define RTC22_REG_ID5 0x2D
114#define RTC22_REG_ID6 0x2E
115#define RTC22_REG_ASTAT 0x2F
116#define RTC22_REG_OCTRL 0x30
117#define RTC22_REG_EXTENSION_ADDRESS 0x3F
118#define RTC22_REG_RAM 0x40
119 // rtc22_reg
121
126
131
136#define RTC22_MONDAY 0x00
137#define RTC22_TUESDAY 0x01
138#define RTC22_WEDNESDAY 0x02
139#define RTC22_THURSDAY 0x03
140#define RTC22_FRIDAY 0x04
141#define RTC22_SATURDAY 0x05
142#define RTC22_SUNDAY 0x06
143
148#define RTC22_DEVICE_ID 0x18
149
155#define RTC22_DEVICE_ADDRESS 0x69
156 // rtc22_set
158
163
168
173#define RTC22_MAP_MIKROBUS( cfg, mikrobus ) \
174 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
175 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
176 cfg.tirq = MIKROBUS( mikrobus, MIKROBUS_CS ); \
177 cfg.psw = MIKROBUS( mikrobus, MIKROBUS_AN ); \
178 cfg.wdi = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
179 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
180 // rtc22_map // rtc22
183
188typedef struct
189{
190 // Output pins
191 digital_out_t wdi;
192
193 // Input pins
194 digital_in_t tirq;
195 digital_in_t psw;
196 digital_in_t int_pin;
197
198 // Modules
199 i2c_master_t i2c;
200
201 // I2C slave address
203
204} rtc22_t;
205
210typedef struct
211{
212 pin_name_t scl;
213 pin_name_t sda;
214
215 pin_name_t tirq;
216 pin_name_t wdi;
217 pin_name_t psw;
218 pin_name_t int_pin;
219
220 uint32_t i2c_speed;
221 uint8_t i2c_address;
222
224
230typedef struct
231{
233 uint8_t second;
234 uint8_t minute;
235 uint8_t hour;
236
238
244typedef struct
245{
246 uint8_t day_of_week;
247 uint8_t day;
248 uint8_t month;
249 uint8_t year;
250
252
257typedef enum
258{
261
263
269
280
294err_t rtc22_init ( rtc22_t *ctx, rtc22_cfg_t *cfg );
295
310err_t rtc22_write_regs ( rtc22_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
311
326err_t rtc22_read_regs ( rtc22_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
327
340err_t rtc22_write_reg ( rtc22_t *ctx, uint8_t reg, uint8_t data_in );
341
354err_t rtc22_read_reg ( rtc22_t *ctx, uint8_t reg, uint8_t *data_out );
355
365void rtc22_set_wdi_pin ( rtc22_t *ctx, uint8_t state );
366
375uint8_t rtc22_get_psw_pin ( rtc22_t *ctx );
376
386
395uint8_t rtc22_get_int_pin ( rtc22_t *ctx );
396
408
421err_t rtc22_set_time ( rtc22_t *ctx, rtc22_time_t *time );
422
436
449err_t rtc22_set_date ( rtc22_t *ctx, rtc22_date_t *date );
450
464
465#ifdef __cplusplus
466}
467#endif
468#endif // RTC22_H
469 // rtc22
471
472// ------------------------------------------------------------------------ END
void rtc22_set_wdi_pin(rtc22_t *ctx, uint8_t state)
RTC 22 set WDI pin function.
uint8_t rtc22_get_int_pin(rtc22_t *ctx)
RTC 22 get INT pin function.
err_t rtc22_read_regs(rtc22_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
RTC 22 read regs function.
err_t rtc22_set_time(rtc22_t *ctx, rtc22_time_t *time)
RTC 22 set time function.
err_t rtc22_read_time(rtc22_t *ctx, rtc22_time_t *time)
RTC 22 read time function.
err_t rtc22_init(rtc22_t *ctx, rtc22_cfg_t *cfg)
RTC 22 initialization function.
err_t rtc22_read_date(rtc22_t *ctx, rtc22_date_t *date)
RTC 22 read date function.
err_t rtc22_set_date(rtc22_t *ctx, rtc22_date_t *date)
RTC 22 set date function.
err_t rtc22_read_reg(rtc22_t *ctx, uint8_t reg, uint8_t *data_out)
RTC 22 read reg function.
uint8_t rtc22_get_tirq_pin(rtc22_t *ctx)
RTC 22 get TIRQ pin function.
err_t rtc22_check_communication(rtc22_t *ctx)
RTC 22 check communication function.
uint8_t rtc22_get_psw_pin(rtc22_t *ctx)
RTC 22 get PSW pin function.
err_t rtc22_write_regs(rtc22_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
RTC 22 write regs function.
void rtc22_cfg_setup(rtc22_cfg_t *cfg)
RTC 22 configuration object setup function.
err_t rtc22_write_reg(rtc22_t *ctx, uint8_t reg, uint8_t data_in)
RTC 22 write reg function.
rtc22_return_value_t
RTC 22 Click return value data.
Definition rtc22.h:258
@ RTC22_ERROR
Definition rtc22.h:260
@ RTC22_OK
Definition rtc22.h:259
RTC 22 Click configuration object.
Definition rtc22.h:211
pin_name_t psw
Definition rtc22.h:217
pin_name_t wdi
Definition rtc22.h:216
uint32_t i2c_speed
Definition rtc22.h:220
pin_name_t scl
Definition rtc22.h:212
pin_name_t int_pin
Definition rtc22.h:218
pin_name_t tirq
Definition rtc22.h:215
pin_name_t sda
Definition rtc22.h:213
uint8_t i2c_address
Definition rtc22.h:221
RTC 22 Click date object.
Definition rtc22.h:245
uint8_t month
Definition rtc22.h:248
uint8_t day
Definition rtc22.h:247
uint8_t year
Definition rtc22.h:249
uint8_t day_of_week
Definition rtc22.h:246
RTC 22 Click context object.
Definition rtc22.h:189
digital_in_t tirq
Definition rtc22.h:194
digital_in_t psw
Definition rtc22.h:195
digital_in_t int_pin
Definition rtc22.h:196
i2c_master_t i2c
Definition rtc22.h:199
uint8_t slave_address
Definition rtc22.h:202
digital_out_t wdi
Definition rtc22.h:191
RTC 22 Click time object.
Definition rtc22.h:231
uint8_t second
Definition rtc22.h:233
uint8_t minute
Definition rtc22.h:234
uint8_t second_100th
Definition rtc22.h:232
uint8_t hour
Definition rtc22.h:235